package com.cpkso.sprdata.interceptor;

import java.util.Enumeration;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @author wrzhxy@qq.com
 * @date 2017年11月20日
 */
public class AuthorityInterceptor extends HandlerInterceptorAdapter {

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println(" -- afterCompletion");
		super.afterCompletion(request, response, handler, ex);
	}

	@Override
	public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println(" -- afterConcurrentHandlingStarted Handle --");
		super.afterConcurrentHandlingStarted(request, response, handler);
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println(" -- postHandle --");
		super.postHandle(request, response, handler, modelAndView);
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
//		System.out.println(" -- preHandle --");
//		System.out.println("__________________________");
//		Enumeration<String> attrs = request.getAttributeNames();
//		while (attrs.hasMoreElements()) {
//			String attrEle = (String) attrs.nextElement();
//			System.out.println(attrEle);
//		}
//		System.out.println("__________________________");
//		
//		String characterEncoding = request.getCharacterEncoding();
//		System.out.println(characterEncoding);
//		System.out.println("__________________________");
//		
//		String contentType = request.getContentType();
//		System.out.println(contentType);
//		System.out.println("__________________________");
//		
//		String contextPath = request.getContextPath();
//		System.out.println(contextPath);
//		System.out.println("__________________________");
//		
//		Cookie[] cookies = request.getCookies();
//		System.out.println(cookies);
//		System.out.println("__________________________");
//		
//		Enumeration<String> headerNames = request.getHeaderNames();
//		while (headerNames.hasMoreElements()) {
//			String headerName = (String) headerNames.nextElement();
//			System.out.println(headerName);
//			System.out.println(request.getHeader(headerName));
//		}
//		
//		System.out.println("__________________________");
//		String method = request.getMethod();
//		System.out.println("method -- " + method);
//		
//		System.out.println("__________________________");
//		String localAddr = request.getLocalAddr();
//		System.out.println(localAddr);// 本机ip
//		
//		System.out.println("__________________________");
//		Map<String, String[]> parameterMap = request.getParameterMap();
//		Set<Entry<String,String[]>> paramEntrySet = parameterMap.entrySet();
//		for (Entry<String, String[]> paramEntry : paramEntrySet) {
//			System.out.println(paramEntry.getKey());
//			System.out.println(paramEntry.getValue());
//		}
//		
//		System.out.println("__________________________");
//		String remoteAddr = request.getRemoteAddr();		// 用户ip
//		System.out.println(remoteAddr);
//		
//		System.out.println("__________________________");
//		String requestURI = request.getRequestURI(); 		// /lue/g/1
//		System.out.println(requestURI);
//		
//		System.out.println("__________________________");
//		String servletPath = request.getServletPath(); 		// /lue/g/1
//		System.out.println(servletPath);
//		
//		System.out.println("__________________________");
//		ServletContext servletContext = request.getServletContext();
//		System.out.println(servletContext.getRealPath("/"));	// C:\Users\Administrator\AppData\Local\Temp\tomcat-docbase.8847628804907085389.9090\
//		
//		System.out.println("__________________________");
//		HttpSession session = request.getSession();
//		System.out.println(session);
//		
//		System.out.println("__________________________");
		return super.preHandle(request, response, handler);
	}
	
}
